package cn.tedu.restaurant.service.impl;

import cn.tedu.restaurant.entity.Top;
import cn.tedu.restaurant.mapper.TopMapper;
import cn.tedu.restaurant.service.TopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-06
 */
@Service
public class TopServiceImpl extends ServiceImpl<TopMapper, Top> implements TopService {

    @Autowired
    @Resource
    private TopMapper topMapper;


    @Override public void updateCount(Integer uid, Integer flag, String username) {
        Top top = topMapper.findByUid(uid);
        if (top==null){
            return;
        }
        if(flag==0){
            topMapper.updateTop(uid,flag+1,username);
        }else{
            topMapper.updateTop(uid,flag-1,username);
        }
    }

    @Override public Integer getCount() {
        return topMapper.selectTop();
    }

}
